import * as Necessary from "./types/necessary"
import { request } from "@/utils/service"

/** 增 */
export function addFileDataApi(data: Necessary.IAddFileRequestData) {
  return request({
    url: "fileItem/addOne",
    method: "post",
    data
  })
}

/** 删除 */
export function deleteFileDataApi(id: number) {
  return request({
    url: `fileItem/deleteOne?id=${id}`,
    method: "delete"
  })
}
/** 改 */
export function updateFileDataApi(data: Necessary.IUpdateFileRequestData) {
  return request({
    url: `fileItem/updateOne`,
    method: "put",
    data
  })
}

/** 获取列表 */
export function getFileDataApi(data: { page: number; size: number; name: string }) {
  return request<Necessary.GetFileResponseData>({
    url: `fileItem/getList?page=${data.page}&size=${data.size}&name=${data.name}`,
    method: "get"
  })
}

/** 获取某资料项授予列表 */
export function getGrantListApi(id: number) {
  return request<Necessary.GetGrantListResponseData>({
    url: `fileItem/getGrantList?itemId=${id}`,
    method: "get"
  })
}

/** 修改某资料项授予列表 */
export function updateGrantApi(data: Necessary.IUpdateGrantRequestData) {
  return request({
    url: `fileItem/updateGrant`,
    method: "put",
    data
  })
}

/** 获取某单位需要上传的必要资料 */
export function getItemListApi(departmentId: number) {
  return request<Necessary.GetFileItemResponseData>({
    url: `fileItem/getItemList?departmentId=${departmentId}`,
    method: "get"
  })
}

/** 上传文件模板 */
export function uploadTemplateApi(data: FormData) {
  return request<any>({
    url: `fileItem/uploadTemplate`,
    method: "post",
    data,
    headers: {
      "Content-Type": "multipart/form-data"
    }
  })
}
